package com.example.jdimust.util;

import com.example.jdimust.ledger.LedgerCheckBean;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import static com.example.jdimust.main.ui.Dataquery.DataqueryFragment.client;

/**
 * Author: MaZongyang
 * Date: 2021/5/19/0019 17:18
 * Description:
 */
public class MessageCheck {
    public static final MediaType header = MediaType.parse("application/json;charset=utf-8");
    static String messagecheckurl = "https://hzy.graduationproject.xyz/MessageCheck";

    public static String mescheck(String extend, String json) throws IOException {
        RequestBody body = RequestBody.create(header, json);
        Request request = new Request.Builder()
                .url(messagecheckurl + extend)
                .post(body)
                .build();
        Response response = client.newCall(request).execute();
        String rejson = response.body().string();
        String state = null;
        if (response.isSuccessful()) {
//            JSONObject call_json = new JSONObject(callStr);
            Gson gson2 = new Gson();
            LedgerCheckBean ledgercheckbean = gson2.fromJson(rejson, LedgerCheckBean.class);
            String restate = null;
            for (LedgerCheckBean.ResultDTO resultDTO : ledgercheckbean.getResult()){
                state = resultDTO.getState();
            return state;
            }
            return response.body().string();
        } else {
            throw new IOException("Unexpected code " + response);
        }
    }
}

